package com.risk.management.controller;

import com.risk.management.dto.Result;
import com.risk.management.entity.Risk;
import com.risk.management.entity.RiskHistory;
import com.risk.management.entity.User;
import com.risk.management.service.RiskHistoryService;
import com.risk.management.service.RiskService;
import com.risk.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 风险历史记录控制器
 */
@Controller
@RequestMapping("/risk-history")
public class RiskHistoryController {

    @Autowired
    private RiskHistoryService riskHistoryService;

    @Autowired
    private RiskService riskService;

    @Autowired
    private UserService userService;

    /**
     * 风险历史记录列表页面
     */
    @GetMapping("/risk/{riskId}")
    public String list(@PathVariable Long riskId, Model model) {
        Risk risk = riskService.getRiskById(riskId);
        if (risk == null) {
            return "redirect:/risk/list";
        }
        
        List<RiskHistory> histories = riskHistoryService.getRiskHistoriesByRiskId(riskId);
        model.addAttribute("risk", risk);
        model.addAttribute("histories", histories);
        return "risk-history/list";
    }
    
    /**
     * 获取风险历史记录JSON数据
     */
    @GetMapping("/api/risk/{riskId}")
    @ResponseBody
    public Result<List<RiskHistory>> getRiskHistories(@PathVariable Long riskId) {
        List<RiskHistory> histories = riskHistoryService.getRiskHistoriesByRiskId(riskId);
        return Result.success(histories);
    }
} 